﻿<%@ codepage=65001%><% 'UTF-8%>

<% '商品管理%>
<!--#include file="../Include/Common.All.asp"-->
<!--#include file="../Include/Conn.asp"-->
<% call OpenConn%>

<!--#include file="../Include/Common.Security.asp"-->
<!--#include file="../Include/MD5.asp"-->
<!--#include file="../Include/JSON_2.0.2.asp"-->
<!--#include file="../Include/JSON_UTIL_0.1.1.asp"-->



<%

	'定义json对象
	Dim jsonObj,jsonObj_user
	Set jsonObj = jsObject()
	Set jsonObj_user = jsObject()
	
	UserID=ReplaceBadChar(Trim(Session("UserID")))
	
	dim act 
  act=request("act")
 	Dim rsObj,strSql,strSqlTemp
 	set rsObj=Server.CreateObject("ADODB.Recordset")
 	''定义查询字段变量
 	dim id, sendtime, sender, title, incept, content, tag, tagcode
	''查询信息列表
	if "search"=act then
		title=ReplaceBadChar(Trim(request.Form("title")))
		incept=ReplaceBadChar(Trim(request.Form("incept")))
		tag=ReplaceBadChar(Trim(request.Form("tag")))
		tagcode=ReplaceBadChar(Trim(request.Form("tagcode")))
		content=ReplaceUrlBadChar(Trim(request.Form("content")))
		dim page ''当前查询页
		page=ReplaceBadChar(Trim(request.Form("page")))&""
				
		jsonObj("rslist") = ""
		''添加用户信息
		jsonObj_user("UserID") = UserID 
		jsonObj_user("UserName") =ReplaceBadChar(Trim(Session("UserName")))
		Set jsonObj("customer") = jsonObj_user 
	 
		''添加查询结果信息，按照菜单排序
		''Dim rsObj,strSql 
		strSql = "SELECT top 100 PERCENT id ,  sendtime, sender, title, incept,  tag , tagcode, tagcode as orderid1  "
		strSql= strSql & "  FROM T_MSG "   & "WHERE 1=1 "
		If (title <> "") Then strSql=strSql & " and title like '%" & title & "%'  "
		If (content <> "") Then strSql=strSql & " and content like '%" & content & "%'  "
 		If (incept <> "") Then strSql=strSql & " and incepsendert like '%" & incept & "%'  "
 		If (tag <> "") Then strSql=strSql & " and tag like '%" & tag & "%'  "
		strSql=strSql & " ORDER BY orderid1 ,id "
		
		dim TotalRsNum ,PageSizeCur''TotalRsNum总记录数''PageSizeCur当前页记录数
		strSqlTemp = "select count(*)  from ( " & strSql & " ) kksds "
		TotalRsNum = PE_CLng(Conn.Execute(strSqlTemp)(0))
		''PageSize 页的记录数量
		PageSizeCur = PageSize ''当前页记录数
		if (PageSize*PE_CLng(page)>TotalRsNum or 0=TotalRsNum) then ''判断最后一页记录数是否和PageSize相等
			PageSizeCur= TotalRsNum Mod PageSize ''该页的时间记录数
		end if

		strSqlTemp = " SELECT ttkkk.* FROM (SELECT TOP " & CStr(PageSizeCur)
		strSqlTemp = strSqlTemp & "  mmsss.* FROM (SELECT TOP " & CStr(PageSize*PE_CLng(page)) & " nnfff.* FROM ( " 
		strSqlTemp = strSqlTemp &	strSql  
		strSqlTemp = strSqlTemp &  " ) nnfff) mmsss  ORDER BY mmsss.orderid1 DESC) ttkkk ORDER BY ttkkk.orderid1"
		Set jsonObj("rslist") = QueryToJSON(Conn, strSqlTemp)
		
		''添加分页信息
		'定义json对象
		Dim jsonObj_page
		Set jsonObj_page = jsObject()
			jsonObj_page("PageCur") = Page ''当前页	
			jsonObj_page("PageSizeCur") = PageSizeCur ''当前页记录数
			if (0=TotalRsNum  mod PageSize  ) then
				jsonObj_page("PageTotalNum")= TotalRsNum\PageSize''总页数
			else
				jsonObj_page("PageTotalNum")= TotalRsNum\PageSize+1''总页数
			end if
		Set jsonObj("page") = jsonObj_page 
	 
	
 	elseif "add"=act then
 			jsonObj("msg") = "&#x64CD;&#x4F5C;&#x5931;&#x8D25;&#xFF0C;&#x8BF7;&#x91CD;&#x8BD5;..."'''' "操作失败，请重试..."
			jsonObj("success") = 0'"false"

''添加信息

			id=ReplaceBadChar(Trim(request.Form("id")))
			sender=ReplaceBadChar(ReplaceBadChar(Trim(Session("UserName"))))
			title=ReplaceBadChar(Trim(request.Form("title")))
			incept=ReplaceBadChar(Trim(request.Form("incept")))
			''content=request.Form("content")
			tag=ReplaceBadChar(Trim(request.Form("tag")))				
			tagcode=ReplaceBadChar(Trim(request.Form("tagcode")))	
 
			''Dim rsObj,strSql
			strSql = "Select  * from T_MSG where id='"&id&"' "
			''Response.Write strSql&"-----"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				rsObj.AddNew ''如果没记录新增，有记录update	
				strSql = "select ISNULL(MAX(id), 0)  from T_MSG  "
				id = PE_CLng(Conn.Execute(strSql)(0)) + 1
			end if				
			''rsObj("id") = PE_CLng(id)
			rsObj("sender") = sender
			rsObj("title") = title
			rsObj("incept") = incept
			''rsObj("content") = content
			rsObj("tag") = tag
			rsObj("tagcode") = tagcode
			rsObj.Update
			rsObj.close
			''Set rsObj = Nothing
		 
			jsonObj("msg") = "添加成功，正在跳转..."
			jsonObj("success") = 1'"success"
			jsonObj("url") = "msgs.asp"
	 	 		
 elseif "edit"=act then
 			jsonObj("msg") = "操作失败，请重试..."
			jsonObj("success") = 0'"false"
			
 
''修改信息

			id=ReplaceBadChar(Trim(request.Form("id")))
			sender=ReplaceBadChar(ReplaceBadChar(Trim(Session("UserName"))))
			title=ReplaceBadChar(Trim(request.Form("title")))
			incept=ReplaceBadChar(Trim(request.Form("incept")))
			tag=request.Form("tag")
			tagcode=request.Form("tagcode")
			content=request.Form("msg_content")

			''content=Server.HTMLEncode(content)
			tag=ReplaceBadChar(Trim(request.Form("tag")))			
		 

 
			''Dim rsObj,strSql
			''set rsObj=Server.CreateObject("ADODB.Recordset")
			strSql = "Select  * from T_MSG where id='"&id&"' "
			''Response.Write strSql&"-----"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				jsonObj("msg") =  "操作失败，请重试..."
				jsonObj("success") = 0'"false"
					rsObj.close
			else				
				''rsObj("id") = PE_CLng(id)
				rsObj("sender") = sender
				rsObj("title") = title
				rsObj("incept") = incept
				rsObj("content") = content
				rsObj("tagcode") = tagcode
				rsObj("tag") = tag
				rsObj.Update
				rsObj.close
			 

				jsonObj("msg") =  "添加成功，正在跳转..."
				jsonObj("success") = 1'"success"
				jsonObj("url") = "msgs.asp"
	 		end if	
	response.redirect "msgs.asp" 	
 
 elseif "delete"=act then
''删除记录
    Dim  RowCount 
		id=ReplaceBadChar(Trim(request.Form("id"))) 
		RowCount = 0
    jsonObj("success") = 0 'false
    jsonObj("msg") = "记录删除失败。" 
 
    RowCount = 0
    If (id <> "" ) Then 
    	Conn.Execute ("delete from T_MSG where id='"&id&"'"), RowCount	    
	    If RowCount > 0 Then
	        jsonObj("msg") = "删除成功，正在跳转..." 
					jsonObj("success") = 1'"success"
					jsonObj("url") = "msgs.asp"
	    End If
    End If
 
  

	end If''''删除记录
 			
 	Set rsObj = Nothing


	'输出json对象
	jsonObj.Flush
	''Response.Write strSql&"-----"
 '释放数据库链接
	call CloseConn

''{
''    rslist : [ { name: "mac", desc: "computer",     
''                   price: 1000, quantity: 100, alert:null },
''                 { name: "ipod", desc: "music player", 
''                   price:  200, quantity: 200, alert:"on sale now!" },
''                 { name: "cinema display", desc: "screen",       
''                   price:  800, quantity: 300, alert:"best deal!" } ],
''    customer : { first: "John", last: "Public", level: "gold" }
''}

%>